package org.codeart.map.controller;

import cn.hutool.core.collection.CollectionUtil;
import org.codeart.common.response.TerminalResponse;
import org.codeart.common.response.TraceSearchResponse;
import org.codeart.common.util.R;
import org.codeart.map.service.TerminalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/terminal")
public class TerminalController {
    
    @Autowired
    private TerminalService terminalService;
    
    @PostMapping("/add")
    public R<TerminalResponse> add(@RequestParam("name") String name, @RequestParam("desc") String desc) {
        TerminalResponse terminalResponse = terminalService.add(name, desc);
        return R.ok(terminalResponse);
    }
    
    @GetMapping("/around-search")
    public R<List<TerminalResponse>> aroundSearch(@RequestParam("center") String center, @RequestParam("radius") Integer radius) {
        List<TerminalResponse> list = terminalService.aroundSearch(center, radius);
        if (CollectionUtil.isNotEmpty(list)) {
            return R.ok(list);
        }
        return R.fail("终端周边搜索失败");
    }

    /**
     * 轨迹查询
     */
    @PostMapping("/trace-search")
    public R<TraceSearchResponse> traceSearch(@RequestParam("tid") String tid, @RequestParam("startTime") Long startTime,
                               @RequestParam("endTime") Long endTime) {
        TraceSearchResponse response = terminalService.traceSearch(tid, startTime, endTime);
        return R.ok(response);
    }
    

}
